package com.qf.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

/**
 * 注解式开发
 * @ControllerAdvice:注解式开发 异常处理实现类 注解
 *
 * @author lixu
 */
//@ControllerAdvice
public class MyExceptionHandler {


    /**
     * 算术异常的处理
     */
    @ExceptionHandler(value = {ArithmeticException.class})
    public String ArithmeticExceptionHandler(ArithmeticException arithmeticException, Model model){
        //处理
/*        ModelAndView mav = new ModelAndView();
        mav.setViewName("error/error");
        mav.addObject("message","不好意思，我迷路！ArithmeticException");
        return mav;*/

        model.addAttribute("message","不好意思，我迷路！ArithmeticException");
        return "error/error";
    }
    /**
     * IO异常的处理
     */
    @ExceptionHandler(value = {IOException.class})
    public String IOExceptionHandler(IOException ioException, Model model){
        model.addAttribute("message","不好意思，我迷路！IOException");
        return "error/error";
    }
    /**
     * 大异常的处理  : 托底异常处理
     */
    @ExceptionHandler(value = {Exception.class})
    public String exceptionHandler(Exception exception, Model model){
        model.addAttribute("message","不好意思，我迷路！Exception");
        return "error/error";
    }


}
